function [list_of_regions]=which_region_from_ground_truth(ground_truth_map, reg_indices_cell)

% This function returns, for each region, what is the label it belongs to,
% according to the Ground Truth matrix.
% In case less than X% (defined) of region' pixels belong to single label, we 
% don't consider it as belonging to any laebl.

% Function Inputs:
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% ground_truth_map -  the ground truth map to extract from it the truly labels of the regions.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
% reg_indices_cell -  cell of arrays, each array contains the region's indices from the original image.
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

% Function Outputs:
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%  list_of_regions - array of region's labels, according to the ground truth map
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

% Defines the minimal percent of pixels that region can have from a label, 
% and still be regarded as part of the label
min_percent = 0.90; 

reg_count=length(reg_indices_cell{1,1});
list_of_regions=zeros(1,reg_count);
for reg_num=1:reg_count
    
        % extracting the region from the ground_truth_map
		ground_labels=ground_truth_map(reg_indices_cell{1,1}{1,reg_num});
        len_labels=length(ground_labels);
        sky_pixels  = length(find(ground_labels==1));
        walls_or_trees_pixels = length(find(ground_labels==2));
        roof_pixels = length(find(ground_labels==3));
        ground_pixels = length(find(ground_labels==4));
         
        % making the label decision
        if ((sky_pixels/len_labels)>= min_percent)
            list_of_regions(reg_num) = 1;
        end
        if ((walls_or_trees_pixels/len_labels)>= min_percent)
            list_of_regions(reg_num) = 2;
        end
        if ((roof_pixels/len_labels)>= min_percent)
            list_of_regions(reg_num) = 3;
        end
        if ((ground_pixels/len_labels) >= min_percent)
            list_of_regions(reg_num) = 4;
        end
end